package com.ruoyi.tb.lmt.controller;

import java.util.List;
import java.util.Arrays;
import java.util.Map;

import com.ruoyi.tb.lmt.domain.TbWorkcategory;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.tb.lmt.domain.vo.TbWorkcategoryVo;
import com.ruoyi.tb.lmt.domain.bo.TbWorkcategoryBo;
import com.ruoyi.tb.lmt.service.ITbWorkcategoryService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 检修类别
 *
 * @author ruoyi
 * @date 2023-11-30
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/xha-lmt/workcategory")
public class TbWorkcategoryController extends BaseController {

    private final ITbWorkcategoryService iTbWorkcategoryService;

    /**
     * 查询检修类别列表
     */
//    @SaCheckPermission("xha-lmt:workcategory:list")
//    @GetMapping("/list")
//    public TableDataInfo<TbWorkcategoryVo> list(TbWorkcategoryBo bo, PageQuery pageQuery) {
//        return iTbWorkcategoryService.queryPageList(bo, pageQuery);
//    }
    /*
     * @Author jiaxiufeng
     * @Description 大机配属树
     * @Date 11:15 2023/12/4
     * @Param id
     * @return
     **/
    //@SaCheckPermission("xha-lmt:workcategory:query")
    @GetMapping("/list")
    public R<List<TbWorkcategory>> treeBylmtType(@NotEmpty(message = "大机类型不能为空")
                                                 @RequestParam String lmtType) {
        return R.ok(iTbWorkcategoryService.treeBylmtType(lmtType));
    }
    /**
     * 导出检修类别列表
     */
    @SaCheckPermission("xha-lmt:workcategory:export")
    @Log(title = "检修类别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TbWorkcategoryBo bo, HttpServletResponse response) {
        List<TbWorkcategoryVo> list = iTbWorkcategoryService.queryList(bo);
        ExcelUtil.exportExcel(list, "检修类别", TbWorkcategoryVo.class, response);
    }

    /**
     * 获取检修类别详细信息
     *
     * @param ID 主键
     */
    @SaCheckPermission("xha-lmt:workcategory:query")
    @GetMapping("/{ID}")
    public R<TbWorkcategoryVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long ID) {
        return R.ok(iTbWorkcategoryService.queryById(ID));
    }

    /**
     * 新增检修类别
     */
    @SaCheckPermission("xha-lmt:workcategory:add")
    @Log(title = "检修类别", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<TbWorkcategory> add(@Validated(AddGroup.class) @RequestBody TbWorkcategoryBo bo) {
        return R.ok(iTbWorkcategoryService.insertByBoRVo(bo));
    }

    /**
     * 修改检修类别
     */
    @SaCheckPermission("xha-lmt:workcategory:edit")
    @Log(title = "检修类别", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TbWorkcategoryBo bo) {
        return toAjax(iTbWorkcategoryService.updateByBo(bo));
    }

    /**
     * 删除检修类别
     *
     * @param IDs 主键串
     */
    @SaCheckPermission("xha-lmt:workcategory:remove")
    @Log(title = "检修类别", businessType = BusinessType.DELETE)
    @DeleteMapping("/{IDs}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] IDs) {
        return toAjax(iTbWorkcategoryService.deleteWithValidByIds(Arrays.asList(IDs), true));
    }
    @SaCheckPermission("xha-lmt:workcategory:removeByTree")
    @Log(title = "检修类别", businessType = BusinessType.DELETE)
    @DeleteMapping("/removeByTree/{id}")
    public R<Void> removeByTree(@NotEmpty(message = "主键不能为空")
                          @PathVariable String id) {
        return toAjax(iTbWorkcategoryService.removeByTree(id));
    }

    /**
     * @description: 通过大机类型复制数据
     * @author jiaxiufeng
     * @date 2023/12/4 13:54
     * @version 1.0
     */
    @SaCheckPermission("xha-lmt:workcategory:copyBylmtType")
    @Log(title = "检修类别", businessType = BusinessType.INSERT)
    @PostMapping("/copy")
    public R<Void> copy(@RequestBody Map<String,String> lmtTypeMap) {
        return toAjax(iTbWorkcategoryService.copyBylmtType(lmtTypeMap));
    }
}
